const
    errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware'),
    noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware'),
    path = require('path'),
    config = require('./webpack.config.dev'),
    paths = require('./paths'),
    protocol = process.env.HTTPS === 'true' ? 'https' : 'http',
    host = process.env.HOST || '0.0.0.0'
;

module.exports = function(proxy, allowedHost) {
    return {
        disableHostCheck: !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
        compress: true,
        clientLogLevel: 'none',
        contentBase: paths.appPublic,
        watchContentBase: true,
        hot: true,
        publicPath: config.output.publicPath,
        quiet: true,
        watchOptions: {
            ignored: new RegExp(`^(?!${path.normalize(paths.appSrc + '/').replace(/[\\]+/g, '\\\\')}).+[\\\\/]node_modules[\\\\/]`, 'g')
        },
        https: protocol === 'https',
        host: host,
        overlay: false,
        historyApiFallback: {
            disableDotRule: true
        },
        public: allowedHost,
        proxy,
        before(app) {
            app.use(errorOverlayMiddleware());
            app.use(noopServiceWorkerMiddleware());
        }
    }
}